# source /etc/profile
#
echo -------------------------------------
namespace="abp-vnext" 
microservices="MicroserviceDemo/microservices/"
applications="MicroserviceDemo/applications/"
gateways="MicroserviceDemo/gateways/"

dockerfileMicroServices1=$microservices"BloggingService.Host"
dockerfileMicroServices2=$microservices"IdentityService.Host"
dockerfileMicroServices3=$microservices"ProductService.Host"
dockerfileMicroServices4=$microservices"TenantManagementService.Host"
dockerfileGateways1=$gateways"BackendAdminAppGateway.Host"
dockerfileGateways2=$gateways"InternalGateway.Host"
dockerfileGateways3=$gateways"PublicWebSiteGateway.Host"
dockerfileApplications1=$applications"AuthServer.Host"
dockerfileApplications2=$applications"BackendAdminApp.Host"
dockerfileApplications3=$applications"PublicWebSite.Host"

projectsMicroServices1="blogging-service"
projectsMicroServices2="identity-service"
projectsMicroServices3="product-service"
projectsMicroServices4="tenant-management-service"
projectsGateways1="backend-admin-app-gateway"
projectsGateways2="internal-gateway"
projectsGateways3="public-web-site-gateway"
projectsApplications1="auth-server"
projectsApplications2="backend-admin-app"
projectsApplications3="public-web-site"

echo $BUILD_NUMBER

dockerImageMicroServices1=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectsMicroServices1":v0."$BUILD_NUMBER
dockerImageMicroServices2=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectMicroServices2":v0."$BUILD_NUMBER
dockerImageMicroServices3=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectMicroServices3":v0."$BUILD_NUMBER
dockerImageMicroServices4=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectMicroServices4":v0."$BUILD_NUMBER
dockerImageGateways1=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectGateways1":v0."$BUILD_NUMBER
dockerImageGateways2=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectGateways2":v0."$BUILD_NUMBER
dockerImageGateways3=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectGateways3":v0."$BUILD_NUMBER
dockerImageApplications1=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectApplications1":v0."$BUILD_NUMBER
dockerImageApplications2=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectApplications2":v0."$BUILD_NUMBER
dockerImageApplications3=$LOCAL_HARBOR_BASE_URL"/"$namespace"/"$projectApplications3":v0."$BUILD_NUMBER

docker build -f $dockerfileMicroServices1"/"Dockerfile -t $dockerImageMicroServices1 .
docker build -f $dockerfileMicroServices2"/"Dockerfile -t $dockerImageMicroServices2 .
docker build -f $dockerfileMicroServices3"/"Dockerfile -t $dockerImageMicroServices3 .
docker build -f $dockerfileMicroServices4"/"Dockerfile -t $dockerImageMicroServices4 .
docker build -f $dockerfileGateways1"/"Dockerfile      -t $dockerImageGateways1 .
docker build -f $dockerfileGateways2"/"Dockerfile      -t $dockerImageGateways2 .
docker build -f $dockerfileGateways3"/"Dockerfile      -t $dockerImageGateways3 .
docker build -f $dockerfileApplications1"/"Dockerfile  -t $dockerImageApplications1 .
docker build -f $dockerfileApplications2"/"Dockerfile  -t $dockerImageApplications2 .
docker build -f $dockerfileApplications3"/"Dockerfile  -t $dockerImageApplications3 .

docker push $dockerImageMicroServices1
docker push $dockerImageMicroServices2
docker push $dockerImageMicroServices3
docker push $dockerImageMicroServices4
docker push $dockerImageGateways1
docker push $dockerImageGateways2
docker push $dockerImageGateways3
docker push $dockerImageApplications1
docker push $dockerImageApplications2
docker push $dockerImageApplications3

docker rmi $dockerImageMicroServices1
docker rmi $dockerImageMicroServices2
docker rmi $dockerImageMicroServices3
docker rmi $dockerImageMicroServices4
docker rmi $dockerImageGateways1
docker rmi $dockerImageGateways2
docker rmi $dockerImageGateways3
docker rmi $dockerImageApplications1
docker rmi $dockerImageApplications2
docker rmi $dockerImageApplications3

rancher kubectl set image deployment/$projectsMicroServices1   $projectsMicroServices1=$dockerImageMicroServices1  -n $namespace 
rancher kubectl set image deployment/$projectsMicroServices2   $projectsMicroServices2=$dockerImageMicroServices2  -n $namespace
rancher kubectl set image deployment/$projectsMicroServices3   $projectsMicroServices3=$dockerImageMicroServices3  -n $namespace
rancher kubectl set image deployment/$projectsMicroServices4   $projectsMicroServices4=$dockerImageMicroServices4  -n $namespace
rancher kubectl set image deployment/$projectsGateways1        $projectsGateways1     =$dockerImageGateways1       -n $namespace
rancher kubectl set image deployment/$projectsGateways2        $projectsGateways2     =$dockerImageGateways2       -n $namespace
rancher kubectl set image deployment/$projectsGateways3        $projectsGateways3     =$dockerImageGateways3       -n $namespace
rancher kubectl set image deployment/$projectsApplications1    $projectsApplications1 =$dockerImageApplications1   -n $namespace
rancher kubectl set image deployment/$projectsApplications2    $projectsApplications2 =$dockerImageApplications2   -n $namespace
rancher kubectl set image deployment/$projectsApplications3    $projectsApplications3 =$dockerImageApplications3   -n $namespace
